package com.sunday.haowushop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.haowushop.R;
import com.sunday.haowushop.entity.HelpList;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by 刘涛 on 2017/7/6.
 */

public class HelpListAdapter extends RecyclerView.Adapter {


    private Context mContext;
    private List<HelpList> dataSet = new ArrayList<>();


    public HelpListAdapter(Context context, List<HelpList> datas) {
        this.mContext = context;
        this.dataSet = datas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_help_list_item, null);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        ListHolder listHolder= (ListHolder) holder;
        HelpList helpList=dataSet.get(position);
        listHolder.btnTotal.setText(helpList.getName());
        if (!TextUtils.isEmpty(helpList.getImage())){
            Glide.with(mContext)
                    .load(helpList.getImage())
                    .error(R.mipmap.ic_default)
                    .into(listHolder.helpImg);
        }
        ArrayList<TextView> textList=new ArrayList<>();
        textList.add(listHolder.item1);
        textList.add(listHolder.item2);
        textList.add(listHolder.item3);
        textList.add(listHolder.item4);
        if (!helpList.getList().isEmpty())
        {
            for (int i=0;i<4;i++){
                if (helpList.getList().size()>i){
                    textList.get(i).setText(helpList.getList().get(i).getName());

                }else {
                    textList.get(i).setText("");
                }
            }
        }

    }

    @Override
    public int getItemCount() {
        return dataSet.size();
    }

    class ListHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.help_img)
        ImageView helpImg;
        @Bind(R.id.btn_total)
        TextView btnTotal;
        @Bind(R.id.item1)
        TextView item1;
        @Bind(R.id.item2)
        TextView item2;
        @Bind(R.id.item3)
        TextView item3;
        @Bind(R.id.item4)
        TextView item4;

        public ListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
